package com.HospitalOutpatient.service.impl;

import com.HospitalOutpatient.dao.UserDao;
import com.HospitalOutpatient.entity.User;
import com.HospitalOutpatient.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public User getUserById(String userId) {
        return userDao.selectUserById(userId);
    }
    @Override
    public boolean loginUser(User user) {
        return userDao.selectUserByNameAndWord(user) != null;
    }
    @Override
    public User getUserByName(String userName) {
        return userDao.selectUserByName(userName);
    }
    @Override
    public boolean registerUser(User user) {
        User newUser = getUserByName(user.getUserName());
        if(newUser != null){
            return false;
        }

        return userDao.insertUser(user) >= 1;
    }
}
